class Particle
  attr_accessor :x,:y, :graphics_name, :xdir,:ydir, :r, :rdir, :scale, :growth, :fadeout
  def initialize(level, x,y, graphics_name, xdir=0.0,ydir=0.0, r=0.0, rdir=0.0, scale=1.0, growth=0.0, fadeout=5, blitmode=:additive)
    @x = x
    @y = y
    @graphics_name = graphics_name
    @image_index = rand(Tiles[@graphics_name].size)
    @xdir = xdir
    @ydir = ydir
    @r = r
    @rdir = rdir
    @scale = scale
    @growth = growth
    @alpha = 255
    #@color = Gosu::Color.new(@alpha,255,255, 255)
    @color = Gosu::Color.new(255,255,255, @alpha)
    @fadeout = fadeout
    @level = level
    @blitmode = blitmode
    
    #$game.object_space << self
  end
  
  def update(scrollx=0.0)
    @x += @xdir
    @y += @ydir
    @r += @rdir
    @scale += @growth
    @alpha -= @fadeout
    @color.alpha = [@alpha, 0].max
    
    return false if(@y > 480)
    return false if(@y < 0)
    return false if(@scale <= 0)
    return false if(@alpha <= 0)
    
    return true
  end
  
  def draw(scrollx=0.0)
    #Tiles[@graphics_name][@image_index].draw_rot(@x-scrollx, @y, @level, @r, 0.5,0.5, @scale,@scale, @color)
    Tiles[@graphics_name][@image_index].draw_rot(@x-scrollx, @y, @level, @r, 0.5,0.5, @scale,@scale, @color, @blitmode)
  end
end